﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Shop_CarriageType_Edit : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    { 
        
        if (!IsPostBack)
        {
            hType.Value = Shove._Web.Utility.GetRequest("Type");
            hID.Value = Shove._Web.Utility.GetRequest("ID");
            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    protected override void OnLoad(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url
        isAtFramePageLogin = true;                              //是框架页

        //RequestCompetences = Competences.BuildCompetencesList(Competences.);//页面权限

        base.OnLoad(e);
    }

    #endregion

    private void BindData()
    {
        long ID = Shove._Convert.StrToInt(hID.Value, 0);

        if (hType.Value == "Edit")
        {
            DataTable dt = new DAL.Tables.tbl_Site_CarriageType().Open("[ID],TypeName,(case when IsUse = 1 then '1' else '0' end) as IsUseType,Money", "[ID]=" + ID, "");

            if (dt != null && dt.Rows.Count > 0)
            {
                tbCarriageTypeName.Text = dt.Rows[0]["TypeName"].ToString();
                this.dlUse.SelectedValue =dt.Rows[0]["IsUseType"].ToString();
                this.tbMoney.Text = dt.Rows[0]["Money"].ToString();
            }
        }
    }

    protected void btnOK_Click(object sender, EventArgs e)
    {
        btnOK.Enabled = false;
        long ID = Shove._Convert.StrToInt(hID.Value, 0);
        DAL.Tables.tbl_Site_CarriageType table = new DAL.Tables.tbl_Site_CarriageType();
        table.TypeName.Value = tbCarriageTypeName.Text;
        table.IsUse.Value =Shove._Convert.StrToInt(dlUse.SelectedValue,0);
        table.Money.Value = this.tbMoney.Text;

        if (hType.Value == "Edit")
        {
            long i = table.Update("[ID]=" + ID);

            if (i >= 0)
            {
                Shove._Web.JavaScript.Alert(this.Page, "配送方式修改成功！");
                return;
            }          
        }
        else if (hType.Value == "Add")
        {
            long i = table.Insert();

            if (i >= 0)
            {
                Shove._Web.JavaScript.Alert(this.Page, "配送方式新增成功！");
                return;
            }          
        }

    }

}